package config

import (
	"common/helper"
	"database/sql"
	"fmt"
)

/*
滚屏播报配置
*/

type CfgBroadcastItem struct {
	Id        int     `db:"id" json:"id"`                 // id
	Type      int     `db:"type" json:"type"`             // 分类  1=提款类型 2=中奖类型 3=公告类型
	Phone     string  `db:"phone" json:"phone"`           // 手机号
	Amount    float64 `db:"amount" json:"amount"`         // 金额
	Content   string  `db:"content" json:"content"`       // 公告内容
	ConfirmAt int     `db:"confirm_at" json:"confirm_at"` // 编辑时间
}

type CsBroadcastCfg struct {
}

var cfgBroadcastList []CfgBroadcastItem

func BroadcastCfgSetRow(rows *sql.Rows) {
	var tVal CfgBroadcastItem
	var err error
	err = rows.Scan(&tVal.Id, &tVal.Type, &tVal.Phone, &tVal.Amount, &tVal.Content, &tVal.ConfirmAt)
	//err = rows.Scan(&tVal.Id, &tVal.Type, &tVal.Content, &tVal.ConfirmAt)
	if err != nil {
		helper.InfoLog("BroadcastCfgSetRow,scan err")
		return
	}

	cfgBroadcastList = append(cfgBroadcastList, tVal)
}

func BroadcastCfgRemove() {
	cfgBroadcastList = []CfgBroadcastItem{}
}

func (that *CsBroadcastCfg) GetCfg() []CfgBroadcastItem {
	var items []CfgBroadcastItem
	var item CfgBroadcastItem
	for _, i := range cfgBroadcastList {
		item.Id = i.Id
		item.Type = i.Type
		item.Phone = i.Phone
		item.Amount = i.Amount
		item.ConfirmAt = i.ConfirmAt
		if i.Type == 1 {
			item.Content = i.Phone + " acabou de retirar " + fmt.Sprintf("%.2f", i.Amount) + " BRL"
		} else if i.Type == 2 {
			item.Content = i.Phone + " acaba de ganhar " + fmt.Sprintf("%.2f", i.Amount) + " BRL"
		} else {
			item.Content = i.Content
		}
		items = append(items, item)

	}

	return items
}
